package org.example.predicate;

import org.springframework.cloud.gateway.handler.predicate.AbstractRoutePredicateFactory;
import org.springframework.web.server.ServerWebExchange;
import java.util.Arrays;
import java.util.List;
import java.util.function.Predicate;

/*@Component*/
public class KeywordRoutePredicateFactory extends AbstractRoutePredicateFactory<KeywordRoutePredicateFactory.Config> {

    public KeywordRoutePredicateFactory() {
        super(Config.class);
    }

    @Override
    public List<String> shortcutFieldOrder() {
        return Arrays.asList("keyword");
    }

    @Override
    public Predicate<ServerWebExchange> apply(Config config) {
        System.out.println(config.getKeyword());
        return exchange -> {
            System.out.println(exchange.getRequest().getURI().getPath().contains(config.getKeyword()));
            System.out.println(config.getKeyword());
            return exchange.getRequest().getURI().getPath().contains(config.getKeyword());
        };
    }

    public static class Config {
        private String keyword;
        public Config()
        {
        }
        public Config(String keyword){
            this.keyword=keyword;
        }

        public String getKeyword() {
            return keyword;
        }

        public void setKeyword(String keyword) {
            this.keyword = keyword;
        }
    }
}

